home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1995 November / Macworld Nov ’95.toast / Developers / Flex 2.5.2 / flex-2.5.2 / parse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  26.9 KB  |  1,325 lines  |  [TEXT/MPS ]

  1. #ifndef lint
  2. static char yysccsid[] = "@(#)yaccpar    1.9 CEH (Berkeley) 27/04/95";
  3. #endif
  4. #define YYBYACC 1
  5. #define YYMAJOR 1
  6. #define YYMINOR 9
  7. #define yyclearin (yychar=(-1))
  8. #define yyerrok (yyerrflag=0)
  9. #define YYRECOVERING (yyerrflag!=0)
  10. #define YYPREFIX "yy"
  11. #line 10 "parse.y"
  12. /*-
  13.  * Copyright (c) 1990 The Regents of the University of California.
  14.  * All rights reserved.
  15.  *
  16.  * This code is derived from software contributed to Berkeley by
  17.  * Vern Paxson.
  18.  * 
  19.  * The United States Government has rights in this work pursuant
  20.  * to contract no. DE-AC03-76SF00098 between the United States
  21.  * Department of Energy and the University of California.
  22.  *
  23.  * Redistribution and use in source and binary forms are permitted provided
  24.  * that: (1) source distributions retain this entire copyright notice and
  25.  * comment, and (2) distributions including binaries display the following
  26.  * acknowledgement:  ``This product includes software developed by the
  27.  * University of California, Berkeley and its contributors'' in the
  28.  * documentation or other materials provided with the distribution and in
  29.  * all advertising materials mentioning features or use of this software.
  30.  * Neither the name of the University nor the names of its contributors may
  31.  * be used to endorse or promote products derived from this software without
  32.  * specific prior written permission.
  33.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  34.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  35.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  36.  */
  37.  
  38. /* $Header: /home/daffy/u0/vern/flex/RCS/parse.y,v 2.26 95/03/05 20:37:32 vern Exp $ */
  39.  
  40.  
  41. /* Some versions of bison are broken in that they use alloca() but don't
  42.  * declare it properly.  The following is the patented (just kidding!)
  43.  * #ifdef chud to fix the problem, courtesy of Francois Pinard.
  44.  */
  45. #ifdef YYBISON
  46. /* AIX requires this to be the first thing in the file.  */
  47. #ifdef __GNUC__
  48. #define alloca __builtin_alloca
  49. #else /* not __GNUC__ */
  50. #if HAVE_ALLOCA_H
  51. #include <alloca.h>
  52. #else /* not HAVE_ALLOCA_H */
  53. #ifdef _AIX
  54.  #pragma alloca
  55. #else /* not _AIX */
  56. #ifdef __hpux
  57. void *alloca ();
  58. #else /* not __hpux */
  59. #ifdef __TURBOC__
  60. #include <malloc.h>
  61. #else
  62. char *alloca ();
  63. #endif /* not __TURBOC__ */
  64. #endif /* not __hpux */
  65. #endif /* not _AIX */
  66. #endif /* not HAVE_ALLOCA_H */
  67. #endif /* not __GNUC__ */
  68. #endif /* YYBISON */
  69.  
  70. /* Bletch, ^^^^ that was ugly! */
  71.  
  72.  
  73. #include "flexdef.h"
  74. #include <stdarg.h>
  75.  
  76. int pat, scnum, eps, headcnt, trailcnt, anyccl, lastchar, i, rulelen;
  77. int trlcontxt, xcluflg, currccl, cclsorted, varlength, variable_trail_rule;
  78.  
  79. int *scon_stk;
  80. int scon_stk_ptr;
  81.  
  82. static int madeany = false;  /* whether we've made the '.' character class */
  83. int previous_continued_action;    /* whether the previous rule's action was '|' */
  84.  
  85. /* Expand a POSIX character class expression. */
  86. #define CCL_EXPR(func) \
  87.     { \
  88.     int c; \
  89.     for ( c = 0; c < csize; ++c ) \
  90.         if ( isascii(c) && func(c) ) \
  91.             ccladd( currccl, c ); \
  92.     }
  93.  
  94. /* While POSIX defines isblank(), it's not ANSI C. */
  95. #define IS_BLANK(c) ((c) == ' ' || (c) == '\t')
  96.  
  97. /* On some over-ambitious machines, such as DEC Alpha's, the default
  98.  * token type is "long" instead of "int"; this leads to problems with
  99.  * declaring yylval in flexdef.h.  But so far, all the yacc's I've seen
  100.  * wrap their definitions of YYSTYPE with "#ifndef YYSTYPE"'s, so the
  101.  * following should ensure that the default token type is "int".
  102.  */
  103. #define YYSTYPE int
  104.  
  105. #line 105 "y.tab.c"
  106. #define CHAR 257
  107. #define NUMBER 258
  108. #define SECTEND 259
  109. #define SCDECL 260
  110. #define XSCDECL 261
  111. #define NAME 262
  112. #define PREVCCL 263
  113. #define EOF_OP 264
  114. #define OPTION_OP 265
  115. #define OPT_OUTFILE 266
  116. #define OPT_PREFIX 267
  117. #define OPT_YYCLASS 268
  118. #define CCE_ALNUM 269
  119. #define CCE_ALPHA 270
  120. #define CCE_BLANK 271
  121. #define CCE_CNTRL 272
  122. #define CCE_DIGIT 273
  123. #define CCE_GRAPH 274
  124. #define CCE_LOWER 275
  125. #define CCE_PRINT 276
  126. #define CCE_PUNCT 277
  127. #define CCE_SPACE 278
  128. #define CCE_UPPER 279
  129. #define CCE_XDIGIT 280
  130. #define YYERRCODE 256
  131.  
  132.  
  133. #include "Res.h"
  134.  
  135. static const short* yylhs;
  136. static const short* yylen;
  137. static const short* yydefred;
  138. static const short* yydgoto;
  139. static const short* yysindex;
  140. static const short* yyrindex;
  141. static const short* yygindex;
  142. static const short* yytable;
  143. static const short* yycheck;
  144.  
  145.  
  146. void
  147. InitParseArrays (void)
  148. {
  149.     SLoad(yylhs);
  150.     SLoad(yylen);
  151.     SLoad(yydefred);
  152.     SLoad(yydgoto);
  153.     SLoad(yysindex);
  154.     SLoad(yyrindex);
  155.     SLoad(yygindex);
  156.     SLoad(yytable);
  157.     SLoad(yycheck);
  158. }
  159.  
  160. #define YYTABLESIZE 302
  161.  
  162.  
  163. #define YYFINAL 1
  164. #ifndef YYDEBUG
  165. #define YYDEBUG 0
  166. #endif
  167. #define YYMAXTOKEN 280
  168. #if YYDEBUG
  169. char *yyname[] = {
  170. "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  171. 0,0,0,"'\"'",0,"'$'",0,0,0,"'('","')'","'*'","'+'","','","'-'","'.'","'/'",0,0,
  172. 0,0,0,0,0,0,0,0,0,0,"'<'","'='","'>'","'?'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  173. 0,0,0,0,0,0,0,0,0,"'['",0,"']'","'^'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  174. 0,0,0,0,0,0,0,"'{'","'|'","'}'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  175. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  176. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  177. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"CHAR","NUMBER","SECTEND",
  178. "SCDECL","XSCDECL","NAME","PREVCCL","EOF_OP","OPTION_OP","OPT_OUTFILE",
  179. "OPT_PREFIX","OPT_YYCLASS","CCE_ALNUM","CCE_ALPHA","CCE_BLANK","CCE_CNTRL",
  180. "CCE_DIGIT","CCE_GRAPH","CCE_LOWER","CCE_PRINT","CCE_PUNCT","CCE_SPACE",
  181. "CCE_UPPER","CCE_XDIGIT",
  182. };
  183. char *yyrule[] = {
  184. "$accept : goal",
  185. "goal : initlex sect1 sect1end sect2 initforrule",
  186. "initlex :",
  187. "sect1 : sect1 startconddecl namelist1",
  188. "sect1 : sect1 options",
  189. "sect1 :",
  190. "sect1 : error",
  191. "sect1end : SECTEND",
  192. "startconddecl : SCDECL",
  193. "startconddecl : XSCDECL",
  194. "namelist1 : namelist1 NAME",
  195. "namelist1 : NAME",
  196. "namelist1 : error",
  197. "options : OPTION_OP optionlist",
  198. "optionlist : optionlist option",
  199. "optionlist :",
  200. "option : OPT_OUTFILE '=' NAME",
  201. "option : OPT_PREFIX '=' NAME",
  202. "option : OPT_YYCLASS '=' NAME",
  203. "sect2 : sect2 scon initforrule flexrule '\\n'",
  204. "sect2 : sect2 scon '{' sect2 '}'",
  205. "sect2 :",
  206. "initforrule :",
  207. "flexrule : '^' rule",
  208. "flexrule : rule",
  209. "flexrule : EOF_OP",
  210. "flexrule : error",
  211. "scon_stk_ptr :",
  212. "scon : '<' scon_stk_ptr namelist2 '>'",
  213. "scon : '<' '*' '>'",
  214. "scon :",
  215. "namelist2 : namelist2 ',' sconname",
  216. "namelist2 : sconname",
  217. "namelist2 : error",
  218. "sconname : NAME",
  219. "rule : re2 re",
  220. "rule : re2 re '$'",
  221. "rule : re '$'",
  222. "rule : re",
  223. "re : re '|' series",
  224. "re : series",
  225. "re2 : re '/'",
  226. "series : series singleton",
  227. "series : singleton",
  228. "singleton : singleton '*'",
  229. "singleton : singleton '+'",
  230. "singleton : singleton '?'",
  231. "singleton : singleton '{' NUMBER ',' NUMBER '}'",
  232. "singleton : singleton '{' NUMBER ',' '}'",
  233. "singleton : singleton '{' NUMBER '}'",
  234. "singleton : '.'",
  235. "singleton : fullccl",
  236. "singleton : PREVCCL",
  237. "singleton : '\"' string '\"'",
  238. "singleton : '(' re ')'",
  239. "singleton : CHAR",
  240. "fullccl : '[' ccl ']'",
  241. "fullccl : '[' '^' ccl ']'",
  242. "ccl : ccl CHAR '-' CHAR",
  243. "ccl : ccl CHAR",
  244. "ccl : ccl ccl_expr",
  245. "ccl :",
  246. "ccl_expr : CCE_ALNUM",
  247. "ccl_expr : CCE_ALPHA",
  248. "ccl_expr : CCE_BLANK",
  249. "ccl_expr : CCE_CNTRL",
  250. "ccl_expr : CCE_DIGIT",
  251. "ccl_expr : CCE_GRAPH",
  252. "ccl_expr : CCE_LOWER",
  253. "ccl_expr : CCE_PRINT",
  254. "ccl_expr : CCE_PUNCT",
  255. "ccl_expr : CCE_SPACE",
  256. "ccl_expr : CCE_UPPER",
  257. "ccl_expr : CCE_XDIGIT",
  258. "string : string CHAR",
  259. "string :",
  260. };
  261. #endif
  262. #ifndef YYSTYPE
  263. typedef int YYSTYPE;
  264. #endif
  265. #ifdef YYSTACKSIZE
  266. #undef YYMAXDEPTH
  267. #define YYMAXDEPTH    YYSTACKSIZE
  268. #else
  269. #ifdef YYMAXDEPTH
  270. #define YYSTACKSIZE    YYMAXDEPTH
  271. #else
  272. #define YYSTACKSIZE    500
  273. #define YYMAXDEPTH    500
  274. #endif
  275. #endif
  276. int        yydebug, yynerrs, yyerrflag, yychar;
  277. short    *yyssp;
  278. YYSTYPE    *yyvsp;
  279. YYSTYPE    yyval, yylval;
  280. short    yyss[YYSTACKSIZE];
  281. YYSTYPE    yyvs[YYSTACKSIZE];
  282. #define yystacksize    YYSTACKSIZE
  283. #line 769 "parse.y"
  284.  
  285.  
  286. /* build_eof_action - build the "<<EOF>>" action for the active start
  287.  *                    conditions
  288.  */
  289.  
  290. void build_eof_action()
  291.     {
  292.     register int i;
  293.     char action_text[MAXLINE];
  294.  
  295.     for ( i = 1; i <= scon_stk_ptr; ++i )
  296.         {
  297.         if ( sceof[scon_stk[i]] )
  298.             format_pinpoint_message(
  299.                 "multiple <<EOF>> rules for start condition %s",
  300.                 scname[scon_stk[i]] );
  301.  
  302.         else
  303.             {
  304.             sceof[scon_stk[i]] = true;
  305.             sprintf( action_text, "case YY_STATE_EOF(%s):\n",
  306.                 scname[scon_stk[i]] );
  307.             add_action( action_text );
  308.             }
  309.         }
  310.  
  311.     line_directive_out( (FILE *) 0, 1 );
  312.  
  313.     /* This isn't a normal rule after all - don't count it as
  314.      * such, so we don't have any holes in the rule numbering
  315.      * (which make generating "rule can never match" warnings
  316.      * more difficult.
  317.      */
  318.     --num_rules;
  319.     ++num_eof_rules;
  320.     }
  321.  
  322.  
  323. /* format_synerr - write out formatted syntax error */
  324.  
  325. void format_synerr( msg, arg )
  326. char msg[], arg[];
  327.     {
  328.     char errmsg[MAXLINE];
  329.  
  330.     (void) sprintf( errmsg, msg, arg );
  331.     synerr( errmsg );
  332.     }
  333.  
  334.  
  335. /* synerr - report a syntax error */
  336.  
  337. void synerr( str )
  338. char str[];
  339.     {
  340.     syntaxerror = true;
  341.     pinpoint_message( str );
  342.     }
  343.  
  344.  
  345. /* format_warn - write out formatted warning */
  346.  
  347. void format_warn( msg, arg )
  348. char msg[], arg[];
  349.     {
  350.     char warn_msg[MAXLINE];
  351.  
  352.     (void) sprintf( warn_msg, msg, arg );
  353.     warn( warn_msg );
  354.     }
  355.  
  356.  
  357. /* warn - report a warning, unless -w was given */
  358.  
  359. void warn( str )
  360. char str[];
  361.     {
  362.     line_warning( str, linenum );
  363.     }
  364.  
  365. /* format_pinpoint_message - write out a message formatted with one string,
  366.  *                 pinpointing its location
  367.  */
  368.  
  369. void format_pinpoint_message( msg, arg )
  370. char msg[], arg[];
  371.     {
  372.     char errmsg[MAXLINE];
  373.  
  374.     (void) sprintf( errmsg, msg, arg );
  375.     pinpoint_message( errmsg );
  376.     }
  377.  
  378.  
  379. /* pinpoint_message - write out a message, pinpointing its location */
  380.  
  381. void pinpoint_message( str )
  382. char str[];
  383.     {
  384.     line_pinpoint( str, linenum );
  385.     }
  386.  
  387.  
  388. /* line_warning - report a warning at a given line, unless -w was given */
  389.  
  390. void line_warning( str, line )
  391. char str[];
  392. int line;
  393.     {
  394.     char warning[MAXLINE];
  395.  
  396.     if ( ! nowarn )
  397.         {
  398.         sprintf( warning, "warning, %s", str );
  399.         line_pinpoint( warning, line );
  400.         }
  401.     }
  402.  
  403.  
  404. /* line_pinpoint - write out a message, pinpointing it at the given line */
  405.  
  406. void line_pinpoint( str, line )
  407. char str[];
  408. int line;
  409.     {
  410. #ifdef macintosh
  411.     fflush(stdout);
  412.     fprintf( stderr, "File \"%s\"; Line %d\t# %s\n", infilename, line, str );
  413. #else
  414.     fprintf( stderr, "\"%s\", line %d: %s\n", infilename, line, str );
  415. #endif
  416.     }
  417.  
  418.  
  419. /* yyerror - eat up an error message from the parser;
  420.  *         currently, messages are ignore
  421.  */
  422.  
  423. void yyerror( msg )
  424. char msg[];
  425.     {
  426.     }
  427. #line 531 "y.tab.c"
  428. #define YYABORT        goto yyabort
  429. #define YYREJECT    goto yyabort
  430. #define YYACCEPT    goto yyaccept
  431. #define YYERROR        goto yyerrlab
  432.  
  433.  
  434. static void
  435. yyprintf (const char* format, ...)
  436. {
  437.     if (yydebug) {
  438.         va_list ap;
  439.         printf("yydebug: ");
  440.         va_start(ap, format);
  441.         vprintf(format, ap);
  442.         va_end(ap);
  443.     }
  444. }
  445.  
  446.  
  447. int
  448. yyparse (void)
  449. {
  450.     register int yym, yyn, yystate;
  451. #if YYDEBUG
  452.     register char* yys;
  453.     extern char* getenv(const char*);
  454.  
  455.     if (yys = getenv("YYDEBUG")) {
  456.         yyn = *yys;
  457.         if (yyn >= '0' && yyn <= '9')
  458.             yydebug = yyn - '0';
  459.     }
  460. #endif
  461.  
  462.     InitParseArrays();        // CEH
  463.  
  464.     yynerrs = 0;
  465.     yyerrflag = 0;
  466.     yychar = (-1);
  467.  
  468.     yyssp = yyss;
  469.     yyvsp = yyvs;
  470.     *yyssp = yystate = 0;
  471.  
  472. yyloop:
  473.     if (yyn = yydefred[yystate]) goto yyreduce;
  474.     if (yychar < 0) {
  475.         if ((yychar = yylex()) < 0) yychar = 0;
  476. #if YYDEBUG
  477.         if (yydebug) {
  478.             yys = 0;
  479.             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  480.             if (!yys) yys = "illegal-symbol";
  481.             yyprintf("state %d, reading %d (%s)\n", yystate, yychar, yys);
  482.         }
  483. #endif
  484.     }
  485.     if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
  486.             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
  487.     {
  488. #if YYDEBUG
  489.         yyprintf("state %d, shifting to state %d\n", yystate, yytable[yyn]);
  490. #endif
  491.         if (yyssp >= yyss + yystacksize - 1)
  492.             goto yyoverflow;
  493.  
  494.         *++yyssp = yystate = yytable[yyn];
  495.         *++yyvsp = yylval;
  496.         yychar = (-1);
  497.         if (yyerrflag > 0)  --yyerrflag;
  498.         goto yyloop;
  499.     }
  500.     if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
  501.             yyn <= YYTABLESIZE && yycheck[yyn] == yychar) {
  502.         yyn = yytable[yyn];
  503.         goto yyreduce;
  504.     }
  505.     if (yyerrflag) goto yyinrecovery;
  506. #ifdef lint
  507.     goto yynewerror;
  508. #endif
  509. yynewerror:
  510.     yyerror("syntax error");
  511. #ifdef lint
  512.     goto yyerrlab;
  513. #endif
  514. yyerrlab:
  515.     ++yynerrs;
  516. yyinrecovery:
  517.     if (yyerrflag < 3) {
  518.         yyerrflag = 3;
  519.         for (;;) {
  520.             if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
  521.                     yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) {
  522. #if YYDEBUG
  523.                 yyprintf("state %d, error recovery shifting to state %d\n",
  524.                          *yyssp, yytable[yyn]);
  525. #endif
  526.                 if (yyssp >= yyss + yystacksize - 1)
  527.                     goto yyoverflow;
  528.  
  529.                 *++yyssp = yystate = yytable[yyn];
  530.                 *++yyvsp = yylval;
  531.                 goto yyloop;
  532.             } else {
  533. #if YYDEBUG
  534.                 yyprintf("error recovery discarding state %d\n", *yyssp);
  535. #endif
  536.                 if (yyssp <= yyss) goto yyabort;
  537.                 --yyssp;
  538.                 --yyvsp;
  539.             }
  540.         }
  541.     } else {
  542.         if (yychar == 0) goto yyabort;
  543. #if YYDEBUG
  544.         if (yydebug) {
  545.             yys = 0;
  546.             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  547.             if (!yys) yys = "illegal-symbol";
  548.             yyprintf("state %d, error recovery discards token %d (%s)\n",
  549.                      yystate, yychar, yys);
  550.         }
  551. #endif
  552.         yychar = (-1);
  553.         goto yyloop;
  554.     }
  555. yyreduce:
  556. #if YYDEBUG
  557.     yyprintf("state %d, reducing by rule %d (%s)\n", yystate, yyn, yyrule[yyn]);
  558. #endif
  559.     yym = yylen[yyn];
  560.     yyval = yyvsp[1-yym];
  561.     switch (yyn) {
  562. case 1:
  563. #line 106 "parse.y"
  564. { /* add default rule */
  565.             int def_rule;
  566.  
  567.             pat = cclinit();
  568.             cclnegate( pat );
  569.  
  570.             def_rule = mkstate( -pat );
  571.  
  572.             /* Remember the number of the default rule so we
  573.              * don't generate "can't match" warnings for it.
  574.              */
  575.             default_rule = num_rules;
  576.  
  577.             finish_rule( def_rule, false, 0, 0 );
  578.  
  579.             for ( i = 1; i <= lastsc; ++i )
  580.                 scset[i] = mkbranch( scset[i], def_rule );
  581.  
  582.             if ( spprdflt )
  583.                 add_action(
  584.                 "YY_FATAL_ERROR( \"flex scanner jammed\" )" );
  585.             else
  586.                 add_action( "ECHO" );
  587.  
  588.             add_action( ";\n\tYY_BREAK\n" );
  589.             }
  590. break;
  591. case 2:
  592. #line 135 "parse.y"
  593. { /* initialize for processing rules */
  594.  
  595.             /* Create default DFA start condition. */
  596.             scinstal( "INITIAL", false );
  597.             }
  598. break;
  599. case 6:
  600. #line 146 "parse.y"
  601. { synerr( "unknown error processing section 1" ); }
  602. break;
  603. case 7:
  604. #line 150 "parse.y"
  605. {
  606.             check_options();
  607.             scon_stk = allocate_integer_array( lastsc + 1 );
  608.             scon_stk_ptr = 0;
  609.             }
  610. break;
  611. case 8:
  612. #line 158 "parse.y"
  613. { xcluflg = false; }
  614. break;
  615. case 9:
  616. #line 161 "parse.y"
  617. { xcluflg = true; }
  618. break;
  619. case 10:
  620. #line 165 "parse.y"
  621. { scinstal( nmstr, xcluflg ); }
  622. break;
  623. case 11:
  624. #line 168 "parse.y"
  625. { scinstal( nmstr, xcluflg ); }
  626. break;
  627. case 12:
  628. #line 171 "parse.y"
  629. { synerr( "bad start condition list" ); }
  630. break;
  631. case 16:
  632. #line 182 "parse.y"
  633. {
  634.             outfilename = copy_string( nmstr );
  635.             did_outfilename = 1;
  636.             }
  637. break;
  638. case 17:
  639. #line 187 "parse.y"
  640. { prefix = copy_string( nmstr ); }
  641. break;
  642. case 18:
  643. #line 189 "parse.y"
  644. { yyclass = copy_string( nmstr ); }
  645. break;
  646. case 19:
  647. #line 193 "parse.y"
  648. { scon_stk_ptr = yyvsp[-3]; }
  649. break;
  650. case 20:
  651. #line 195 "parse.y"
  652. { scon_stk_ptr = yyvsp[-3]; }
  653. break;
  654. case 22:
  655. #line 200 "parse.y"
  656. {
  657.             /* Initialize for a parse of one rule. */
  658.             trlcontxt = variable_trail_rule = varlength = false;
  659.             trailcnt = headcnt = rulelen = 0;
  660.             current_state_type = STATE_NORMAL;
  661.             previous_continued_action = continued_action;
  662.             in_rule = true;
  663.  
  664.             new_rule();
  665.             }
  666. break;
  667. case 23:
  668. #line 213 "parse.y"
  669. {
  670.             pat = yyvsp[0];
  671.             finish_rule( pat, variable_trail_rule,
  672.                 headcnt, trailcnt );
  673.  
  674.             if ( scon_stk_ptr > 0 )
  675.                 {
  676.                 for ( i = 1; i <= scon_stk_ptr; ++i )
  677.                     scbol[scon_stk[i]] =
  678.                         mkbranch( scbol[scon_stk[i]],
  679.                                 pat );
  680.                 }
  681.  
  682.             else
  683.                 {
  684.                 /* Add to all non-exclusive start conditions,
  685.                  * including the default (0) start condition.
  686.                  */
  687.  
  688.                 for ( i = 1; i <= lastsc; ++i )
  689.                     if ( ! scxclu[i] )
  690.                         scbol[i] = mkbranch( scbol[i],
  691.                                     pat );
  692.                 }
  693.  
  694.             if ( ! bol_needed )
  695.                 {
  696.                 bol_needed = true;
  697.  
  698.                 if ( performance_report > 1 )
  699.                     pinpoint_message(
  700.             "'^' operator results in sub-optimal performance" );
  701.                 }
  702.             }
  703. break;
  704. case 24:
  705. #line 249 "parse.y"
  706. {
  707.             pat = yyvsp[0];
  708.             finish_rule( pat, variable_trail_rule,
  709.                 headcnt, trailcnt );
  710.  
  711.             if ( scon_stk_ptr > 0 )
  712.                 {
  713.                 for ( i = 1; i <= scon_stk_ptr; ++i )
  714.                     scset[scon_stk[i]] =
  715.                         mkbranch( scset[scon_stk[i]],
  716.                                 pat );
  717.                 }
  718.  
  719.             else
  720.                 {
  721.                 for ( i = 1; i <= lastsc; ++i )
  722.                     if ( ! scxclu[i] )
  723.                         scset[i] =
  724.                             mkbranch( scset[i],
  725.                                 pat );
  726.                 }
  727.             }
  728. break;
  729. case 25:
  730. #line 273 "parse.y"
  731. {
  732.             if ( scon_stk_ptr > 0 )
  733.                 build_eof_action();
  734.     
  735.             else
  736.                 {
  737.                 /* This EOF applies to all start conditions
  738.                  * which don't already have EOF actions.
  739.                  */
  740.                 for ( i = 1; i <= lastsc; ++i )
  741.                     if ( ! sceof[i] )
  742.                         scon_stk[++scon_stk_ptr] = i;
  743.  
  744.                 if ( scon_stk_ptr == 0 )
  745.                     warn(
  746.             "all start conditions already have <<EOF>> rules" );
  747.  
  748.                 else
  749.                     build_eof_action();
  750.                 }
  751.             }
  752. break;
  753. case 26:
  754. #line 296 "parse.y"
  755. { synerr( "unrecognized rule" ); }
  756. break;
  757. case 27:
  758. #line 300 "parse.y"
  759. { yyval = scon_stk_ptr; }
  760. break;
  761. case 28:
  762. #line 304 "parse.y"
  763. { yyval = yyvsp[-2]; }
  764. break;
  765. case 29:
  766. #line 307 "parse.y"
  767. {
  768.             yyval = scon_stk_ptr;
  769.  
  770.             for ( i = 1; i <= lastsc; ++i )
  771.                 {
  772.                 int j;
  773.  
  774.                 for ( j = 1; j <= scon_stk_ptr; ++j )
  775.                     if ( scon_stk[j] == i )
  776.                         break;
  777.  
  778.                 if ( j > scon_stk_ptr )
  779.                     scon_stk[++scon_stk_ptr] = i;
  780.                 }
  781.             }
  782. break;
  783. case 30:
  784. #line 324 "parse.y"
  785. { yyval = scon_stk_ptr; }
  786. break;
  787. case 33:
  788. #line 332 "parse.y"
  789. { synerr( "bad start condition list" ); }
  790. break;
  791. case 34:
  792. #line 336 "parse.y"
  793. {
  794.             if ( (scnum = sclookup( nmstr )) == 0 )
  795.                 format_pinpoint_message(
  796.                     "undeclared start condition %s",
  797.                     nmstr );
  798.             else
  799.                 {
  800.                 for ( i = 1; i <= scon_stk_ptr; ++i )
  801.                     if ( scon_stk[i] == scnum )
  802.                         {
  803.                         format_warn(
  804.                             "<%s> specified twice",
  805.                             scname[scnum] );
  806.                         break;
  807.                         }
  808.  
  809.                 if ( i > scon_stk_ptr )
  810.                     scon_stk[++scon_stk_ptr] = scnum;
  811.                 }
  812.             }
  813. break;
  814. case 35:
  815. #line 359 "parse.y"
  816. {
  817.             if ( transchar[lastst[yyvsp[0]]] != SYM_EPSILON )
  818.                 /* Provide final transition \now/ so it
  819.                  * will be marked as a trailing context
  820.                  * state.
  821.                  */
  822.                 yyvsp[0] = link_machines( yyvsp[0],
  823.                         mkstate( SYM_EPSILON ) );
  824.  
  825.             mark_beginning_as_normal( yyvsp[0] );
  826.             current_state_type = STATE_NORMAL;
  827.  
  828.             if ( previous_continued_action )
  829.                 {
  830.                 /* We need to treat this as variable trailing
  831.                  * context so that the backup does not happen
  832.                  * in the action but before the action switch
  833.                  * statement.  If the backup happens in the
  834.                  * action, then the rules "falling into" this
  835.                  * one's action will *also* do the backup,
  836.                  * erroneously.
  837.                  */
  838.                 if ( ! varlength || headcnt != 0 )
  839.                     warn(
  840.         "trailing context made variable due to preceding '|' action" );
  841.  
  842.                 /* Mark as variable. */
  843.                 varlength = true;
  844.                 headcnt = 0;
  845.                 }
  846.  
  847.             if ( lex_compat || (varlength && headcnt == 0) )
  848.                 { /* variable trailing context rule */
  849.                 /* Mark the first part of the rule as the
  850.                  * accepting "head" part of a trailing
  851.                  * context rule.
  852.                  *
  853.                  * By the way, we didn't do this at the
  854.                  * beginning of this production because back
  855.                  * then current_state_type was set up for a
  856.                  * trail rule, and add_accept() can create
  857.                  * a new state ...
  858.                  */
  859.                 add_accept( yyvsp[-1],
  860.                     num_rules | YY_TRAILING_HEAD_MASK );
  861.                 variable_trail_rule = true;
  862.                 }
  863.             
  864.             else
  865.                 trailcnt = rulelen;
  866.  
  867.             yyval = link_machines( yyvsp[-1], yyvsp[0] );
  868.             }
  869. break;
  870. case 36:
  871. #line 414 "parse.y"
  872. { synerr( "trailing context used twice" ); }
  873. break;
  874. case 37:
  875. #line 417 "parse.y"
  876. {
  877.             headcnt = 0;
  878.             trailcnt = 1;
  879.             rulelen = 1;
  880.             varlength = false;
  881.  
  882.             current_state_type = STATE_TRAILING_CONTEXT;
  883.  
  884.             if ( trlcontxt )
  885.                 {
  886.                 synerr( "trailing context used twice" );
  887.                 yyval = mkstate( SYM_EPSILON );
  888.                 }
  889.  
  890.             else if ( previous_continued_action )
  891.                 {
  892.                 /* See the comment in the rule for "re2 re"
  893.                  * above.
  894.                  */
  895.                 warn(
  896.         "trailing context made variable due to preceding '|' action" );
  897.  
  898.                 varlength = true;
  899.                 }
  900.  
  901.             if ( lex_compat || varlength )
  902.                 {
  903.                 /* Again, see the comment in the rule for
  904.                  * "re2 re" above.
  905.                  */
  906.                 add_accept( yyvsp[-1],
  907.                     num_rules | YY_TRAILING_HEAD_MASK );
  908.                 variable_trail_rule = true;
  909.                 }
  910.  
  911.             trlcontxt = true;
  912.  
  913.             eps = mkstate( SYM_EPSILON );
  914.             yyval = link_machines( yyvsp[-1],
  915.                 link_machines( eps, mkstate( '\n' ) ) );
  916.             }
  917. break;
  918. case 38:
  919. #line 460 "parse.y"
  920. {
  921.             yyval = yyvsp[0];
  922.  
  923.             if ( trlcontxt )
  924.                 {
  925.                 if ( lex_compat || (varlength && headcnt == 0) )
  926.                     /* Both head and trail are
  927.                      * variable-length.
  928.                      */
  929.                     variable_trail_rule = true;
  930.                 else
  931.                     trailcnt = rulelen;
  932.                 }
  933.             }
  934. break;
  935. case 39:
  936. #line 478 "parse.y"
  937. {
  938.             varlength = true;
  939.             yyval = mkor( yyvsp[-2], yyvsp[0] );
  940.             }
  941. break;
  942. case 40:
  943. #line 484 "parse.y"
  944. { yyval = yyvsp[0]; }
  945. break;
  946. case 41:
  947. #line 489 "parse.y"
  948. {
  949.             /* This rule is written separately so the
  950.              * reduction will occur before the trailing
  951.              * series is parsed.
  952.              */
  953.  
  954.             if ( trlcontxt )
  955.                 synerr( "trailing context used twice" );
  956.             else
  957.                 trlcontxt = true;
  958.  
  959.             if ( varlength )
  960.                 /* We hope the trailing context is
  961.                  * fixed-length.
  962.                  */
  963.                 varlength = false;
  964.             else
  965.                 headcnt = rulelen;
  966.  
  967.             rulelen = 0;
  968.  
  969.             current_state_type = STATE_TRAILING_CONTEXT;
  970.             yyval = yyvsp[-1];
  971.             }
  972. break;
  973. case 42:
  974. #line 516 "parse.y"
  975. {
  976.             /* This is where concatenation of adjacent patterns
  977.              * gets done.
  978.              */
  979.             yyval = link_machines( yyvsp[-1], yyvsp[0] );
  980.             }
  981. break;
  982. case 43:
  983. #line 524 "parse.y"
  984. { yyval = yyvsp[0]; }
  985. break;
  986. case 44:
  987. #line 528 "parse.y"
  988. {
  989.             varlength = true;
  990.  
  991.             yyval = mkclos( yyvsp[-1] );
  992.             }
  993. break;
  994. case 45:
  995. #line 535 "parse.y"
  996. {
  997.             varlength = true;
  998.             yyval = mkposcl( yyvsp[-1] );
  999.             }
  1000. break;
  1001. case 46:
  1002. #line 541 "parse.y"
  1003. {
  1004.             varlength = true;
  1005.             yyval = mkopt( yyvsp[-1] );
  1006.             }
  1007. break;
  1008. case 47:
  1009. #line 547 "parse.y"
  1010. {
  1011.             varlength = true;
  1012.  
  1013.             if ( yyvsp[-3] > yyvsp[-1] || yyvsp[-3] < 0 )
  1014.                 {
  1015.                 synerr( "bad iteration values" );
  1016.                 yyval = yyvsp[-5];
  1017.                 }
  1018.             else
  1019.                 {
  1020.                 if ( yyvsp[-3] == 0 )
  1021.                     {
  1022.                     if ( yyvsp[-1] <= 0 )
  1023.                         {
  1024.                         synerr(
  1025.                         "bad iteration values" );
  1026.                         yyval = yyvsp[-5];
  1027.                         }
  1028.                     else
  1029.                         yyval = mkopt(
  1030.                             mkrep( yyvsp[-5], 1, yyvsp[-1] ) );
  1031.                     }
  1032.                 else
  1033.                     yyval = mkrep( yyvsp[-5], yyvsp[-3], yyvsp[-1] );
  1034.                 }
  1035.             }
  1036. break;
  1037. case 48:
  1038. #line 575 "parse.y"
  1039. {
  1040.             varlength = true;
  1041.  
  1042.             if ( yyvsp[-2] <= 0 )
  1043.                 {
  1044.                 synerr( "iteration value must be positive" );
  1045.                 yyval = yyvsp[-4];
  1046.                 }
  1047.  
  1048.             else
  1049.                 yyval = mkrep( yyvsp[-4], yyvsp[-2], INFINITY );
  1050.             }
  1051. break;
  1052. case 49:
  1053. #line 589 "parse.y"
  1054. {
  1055.             /* The singleton could be something like "(foo)",
  1056.              * in which case we have no idea what its length
  1057.              * is, so we punt here.
  1058.              */
  1059.             varlength = true;
  1060.  
  1061.             if ( yyvsp[-1] <= 0 )
  1062.                 {
  1063.                 synerr( "iteration value must be positive" );
  1064.                 yyval = yyvsp[-3];
  1065.                 }
  1066.  
  1067.             else
  1068.                 yyval = link_machines( yyvsp[-3],
  1069.                         copysingl( yyvsp[-3], yyvsp[-1] - 1 ) );
  1070.             }
  1071. break;
  1072. case 50:
  1073. #line 608 "parse.y"
  1074. {
  1075.             if ( ! madeany )
  1076.                 {
  1077.                 /* Create the '.' character class. */
  1078.                 anyccl = cclinit();
  1079.                 ccladd( anyccl, '\n' );
  1080.                 cclnegate( anyccl );
  1081.  
  1082.                 if ( useecs )
  1083.                     mkeccl( ccltbl + cclmap[anyccl],
  1084.                         ccllen[anyccl], nextecm,
  1085.                         ecgroup, csize, csize );
  1086.  
  1087.                 madeany = true;
  1088.                 }
  1089.  
  1090.             ++rulelen;
  1091.  
  1092.             yyval = mkstate( -anyccl );
  1093.             }
  1094. break;
  1095. case 51:
  1096. #line 630 "parse.y"
  1097. {
  1098.             if ( ! cclsorted )
  1099.                 /* Sort characters for fast searching.  We
  1100.                  * use a shell sort since this list could
  1101.                  * be large.
  1102.                  */
  1103.                 cshell( ccltbl + cclmap[yyvsp[0]], ccllen[yyvsp[0]], true );
  1104.  
  1105.             if ( useecs )
  1106.                 mkeccl( ccltbl + cclmap[yyvsp[0]], ccllen[yyvsp[0]],
  1107.                     nextecm, ecgroup, csize, csize );
  1108.  
  1109.             ++rulelen;
  1110.  
  1111.             yyval = mkstate( -yyvsp[0] );
  1112.             }
  1113. break;
  1114. case 52:
  1115. #line 648 "parse.y"
  1116. {
  1117.             ++rulelen;
  1118.  
  1119.             yyval = mkstate( -yyvsp[0] );
  1120.             }
  1121. break;
  1122. case 53:
  1123. #line 655 "parse.y"
  1124. { yyval = yyvsp[-1]; }
  1125. break;
  1126. case 54:
  1127. #line 658 "parse.y"
  1128. { yyval = yyvsp[-1]; }
  1129. break;
  1130. case 55:
  1131. #line 661 "parse.y"
  1132. {
  1133.             ++rulelen;
  1134.  
  1135.             if ( caseins && yyvsp[0] >= 'A' && yyvsp[0] <= 'Z' )
  1136.                 yyvsp[0] = clower( yyvsp[0] );
  1137.  
  1138.             yyval = mkstate( yyvsp[0] );
  1139.             }
  1140. break;
  1141. case 56:
  1142. #line 672 "parse.y"
  1143. { yyval = yyvsp[-1]; }
  1144. break;
  1145. case 57:
  1146. #line 675 "parse.y"
  1147. {
  1148.             cclnegate( yyvsp[-1] );
  1149.             yyval = yyvsp[-1];
  1150.             }
  1151. break;
  1152. case 58:
  1153. #line 682 "parse.y"
  1154. {
  1155.             if ( caseins )
  1156.                 {
  1157.                 if ( yyvsp[-2] >= 'A' && yyvsp[-2] <= 'Z' )
  1158.                     yyvsp[-2] = clower( yyvsp[-2] );
  1159.                 if ( yyvsp[0] >= 'A' && yyvsp[0] <= 'Z' )
  1160.                     yyvsp[0] = clower( yyvsp[0] );
  1161.                 }
  1162.  
  1163.             if ( yyvsp[-2] > yyvsp[0] )
  1164.                 synerr( "negative range in character class" );
  1165.  
  1166.             else
  1167.                 {
  1168.                 for ( i = yyvsp[-2]; i <= yyvsp[0]; ++i )
  1169.                     ccladd( yyvsp[-3], i );
  1170.  
  1171.                 /* Keep track if this ccl is staying in
  1172.                  * alphabetical order.
  1173.                  */
  1174.                 cclsorted = cclsorted && (yyvsp[-2] > lastchar);
  1175.                 lastchar = yyvsp[0];
  1176.                 }
  1177.  
  1178.             yyval = yyvsp[-3];
  1179.             }
  1180. break;
  1181. case 59:
  1182. #line 710 "parse.y"
  1183. {
  1184.             if ( caseins && yyvsp[0] >= 'A' && yyvsp[0] <= 'Z' )
  1185.                 yyvsp[0] = clower( yyvsp[0] );
  1186.  
  1187.             ccladd( yyvsp[-1], yyvsp[0] );
  1188.             cclsorted = cclsorted && (yyvsp[0] > lastchar);
  1189.             lastchar = yyvsp[0];
  1190.             yyval = yyvsp[-1];
  1191.             }
  1192. break;
  1193. case 60:
  1194. #line 721 "parse.y"
  1195. {
  1196.             /* Too hard to properly maintain cclsorted. */
  1197.             cclsorted = false;
  1198.             yyval = yyvsp[-1];
  1199.             }
  1200. break;
  1201. case 61:
  1202. #line 728 "parse.y"
  1203. {
  1204.             cclsorted = true;
  1205.             lastchar = 0;
  1206.             currccl = yyval = cclinit();
  1207.             }
  1208. break;
  1209. case 62:
  1210. #line 735 "parse.y"
  1211. { CCL_EXPR(isalnum) }
  1212. break;
  1213. case 63:
  1214. #line 736 "parse.y"
  1215. { CCL_EXPR(isalpha) }
  1216. break;
  1217. case 64:
  1218. #line 737 "parse.y"
  1219. { CCL_EXPR(IS_BLANK) }
  1220. break;
  1221. case 65:
  1222. #line 738 "parse.y"
  1223. { CCL_EXPR(iscntrl) }
  1224. break;
  1225. case 66:
  1226. #line 739 "parse.y"
  1227. { CCL_EXPR(isdigit) }
  1228. break;
  1229. case 67:
  1230. #line 740 "parse.y"
  1231. { CCL_EXPR(isgraph) }
  1232. break;
  1233. case 68:
  1234. #line 741 "parse.y"
  1235. { CCL_EXPR(islower) }
  1236. break;
  1237. case 69:
  1238. #line 742 "parse.y"
  1239. { CCL_EXPR(isprint) }
  1240. break;
  1241. case 70:
  1242. #line 743 "parse.y"
  1243. { CCL_EXPR(ispunct) }
  1244. break;
  1245. case 71:
  1246. #line 744 "parse.y"
  1247. { CCL_EXPR(isspace) }
  1248. break;
  1249. case 72:
  1250. #line 745 "parse.y"
  1251. {
  1252.                 if ( caseins )
  1253.                     CCL_EXPR(islower)
  1254.                 else
  1255.                     CCL_EXPR(isupper)
  1256.                 }
  1257. break;
  1258. case 73:
  1259. #line 751 "parse.y"
  1260. { CCL_EXPR(isxdigit) }
  1261. break;
  1262. case 74:
  1263. #line 755 "parse.y"
  1264. {
  1265.             if ( caseins && yyvsp[0] >= 'A' && yyvsp[0] <= 'Z' )
  1266.                 yyvsp[0] = clower( yyvsp[0] );
  1267.  
  1268.             ++rulelen;
  1269.  
  1270.             yyval = link_machines( yyvsp[-1], mkstate( yyvsp[0] ) );
  1271.             }
  1272. break;
  1273. case 75:
  1274. #line 765 "parse.y"
  1275. { yyval = mkstate( SYM_EPSILON ); }
  1276. break;
  1277. #line 1379 "y.tab.c"
  1278.     }
  1279.     yyssp -= yym;
  1280.     yystate = *yyssp;
  1281.     yyvsp -= yym;
  1282.     yym = yylhs[yyn];
  1283.     if (yystate == 0 && yym == 0) {
  1284. #if YYDEBUG
  1285.         yyprintf("after reduction, shifting from state 0 to state %d\n", YYFINAL);
  1286. #endif
  1287.         yystate = YYFINAL;
  1288.         *++yyssp = YYFINAL;
  1289.         *++yyvsp = yyval;
  1290.         if (yychar < 0) {
  1291.             if ((yychar = yylex()) < 0) yychar = 0;
  1292. #if YYDEBUG
  1293.             if (yydebug) {
  1294.                 yys = 0;
  1295.                 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  1296.                 if (!yys) yys = "illegal-symbol";
  1297.                 yyprintf("state %d, reading %d (%s)\n", YYFINAL, yychar, yys);
  1298.             }
  1299. #endif
  1300.         }
  1301.         if (yychar == 0) goto yyaccept;
  1302.         goto yyloop;
  1303.     }
  1304.     if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
  1305.             yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
  1306.         yystate = yytable[yyn];
  1307.     else
  1308.         yystate = yydgoto[yym];
  1309. #if YYDEBUG
  1310.     yyprintf("after reduction, shifting from state %d to state %d\n", *yyssp, yystate);
  1311. #endif
  1312.     if (yyssp >= yyss + yystacksize - 1)
  1313.         goto yyoverflow;
  1314.  
  1315.     *++yyssp = yystate;
  1316.     *++yyvsp = yyval;
  1317.     goto yyloop;
  1318. yyoverflow:
  1319.     yyerror("yacc stack overflow");
  1320. yyabort:
  1321.     return 1;
  1322. yyaccept:
  1323.     return 0;
  1324. }
  1325.